package com.gxa.service.impl;

import com.gxa.common.JsonResult;
import com.gxa.common.R;
import com.gxa.dao.ServiceDao;
import com.gxa.dao.impl.ServiceDaoImp;
import com.gxa.pojo.Problem;
import com.gxa.pojo.ServiceManagementInfo;
import com.gxa.service.ServiceService;

import java.sql.SQLException;
import java.util.List;

public class ServiceServiceImp implements ServiceService {
private ServiceDao serviceDao =  new ServiceDaoImp();
    @Override
    public JsonResult queryServieProcessingList(Integer currentPage, Integer pageSize, String serviceName, String type) {
        //创建JsonResult对象
        JsonResult jsonResult = new JsonResult();
        //调用dao
        try {
            //总记录数
            Integer totalSize = serviceDao.countServiceProcessingInfo(serviceName,type);
            //处理 limit 参数
            Integer param01 = (currentPage-1)*pageSize;
            Integer param02 = pageSize;
            List<ServiceManagementInfo> list = serviceDao.queryServiceManagementProcessingList(param01,param02,serviceName,type);
            //判断结果
            if(list!=null){
                jsonResult.setCode(0);//查询的数据展示在LayUI的数据表格，响应成功的状态码0
                jsonResult.setMsg("查询成功");
                jsonResult.setCount(totalSize);
                jsonResult.setData(list);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            jsonResult.setCode(500);
            jsonResult.setMsg("系统开小差，请联系管理员！");
        }
        return jsonResult;


    }

    @Override
    public JsonResult queryServieFeedbackList(Integer currentPage, Integer pageSize, String serviceName, String type) {
        //创建JsonResult对象
        JsonResult jsonResult = new JsonResult();
        //调用dao
        try {
            //总记录数
            Integer totalSize = serviceDao.countServiceFeedbackInfo(serviceName,type);
            //处理 limit 参数
            Integer param01 = (currentPage-1)*pageSize;
            Integer param02 = pageSize;
            List<ServiceManagementInfo> list = serviceDao.queryServiceManagementFeedbackList(param01,param02,serviceName,type);
            //判断结果
            if(list!=null){
                jsonResult.setCode(0);//查询的数据展示在LayUI的数据表格，响应成功的状态码0
                jsonResult.setMsg("查询成功");
                jsonResult.setCount(totalSize);
                jsonResult.setData(list);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            jsonResult.setCode(500);
            jsonResult.setMsg("系统开小差，请联系管理员！");
        }
        return jsonResult;
    }

    @Override
    public JsonResult queryServieArchivingList(Integer currentPage, Integer pageSize, String serviceName, String type, Integer service_status) {
        //创建JsonResult对象
        JsonResult jsonResult = new JsonResult();
        //调用dao
        try {
            //总记录数
            Integer totalSize = serviceDao.countServiceArchivingInfo(serviceName,type,service_status);
            //处理 limit 参数
            Integer param01 = (currentPage-1)*pageSize;
            Integer param02 = pageSize;
            List<ServiceManagementInfo> list = serviceDao.queryServiceManagementArchivingList(param01,param02,serviceName,type,service_status);
            //判断结果
            if(list!=null){
                jsonResult.setCode(0);//查询的数据展示在LayUI的数据表格，响应成功的状态码0
                jsonResult.setMsg("查询成功");
                jsonResult.setCount(totalSize);
                jsonResult.setData(list);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            jsonResult.setCode(500);
            jsonResult.setMsg("系统开小差，请联系管理员！");
        }
        return jsonResult;
    }

    @Override
    public JsonResult queryServieManagementList(Integer currentPage, Integer pageSize, String ptitle, String ptype) {
        //创建JsonResult对象
        JsonResult jsonResult = new JsonResult();
        //调用dao
        try {
            //总记录数
            Integer totalSize = serviceDao.countServiceManagementInfo(ptitle,ptype);
            //处理 limit 参数
            Integer param01 = (currentPage-1)*pageSize;
            Integer param02 = pageSize;
            List<Problem> list = serviceDao.queryServiceManagementManagementList(param01,param02,ptitle,ptype);
            //判断结果
            if(list!=null){
                jsonResult.setCode(0);//查询的数据展示在LayUI的数据表格，响应成功的状态码0
                jsonResult.setMsg("查询成功");
                jsonResult.setCount(totalSize);
                jsonResult.setData(list);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            jsonResult.setCode(500);
            jsonResult.setMsg("系统开小差，请联系管理员！");
        }
        return jsonResult;
    }

    @Override
    public R delServiceById(String id) {
        R r = new R();
        try {
            int result = serviceDao.delServiceById(id);
            if(result>0){
                r.setCode(200);
                r.setMsg("删除成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统开小差，请联系管理员");
        }
        return r;
    }

    @Override
    public R delManagementServiceById(String id) {
        R r = new R();
        try {
            int result = serviceDao.delManagementServiceById(id);
            if(result>0){
                r.setCode(200);
                r.setMsg("删除成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统开小差，请联系管理员");
        }
        return r;
    }

    @Override
    public R updateServiceProcessingById(ServiceManagementInfo sm) {
        R r = new R();
        try {
            int result = serviceDao.updateServiceProcessingById(sm);
            if(result>0){
                r.setCode(200);
                r.setMsg("处理成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统开小差，请联系管理员");
        }

        return r;
    }

    @Override
    public R updateServiceFeedbackById(ServiceManagementInfo sm) {
        R r = new R();
        try {
            int result = serviceDao.updateServiceFeedbackById(sm);
            if(result>0){
                r.setCode(200);
                r.setMsg("反馈成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统开小差，请联系管理员");
        }

        return r;
    }

    @Override
    public R updateServiceArchivingById(ServiceManagementInfo sm) {
        R r = new R();
        try {
            int result = serviceDao.updateServiceArchivingById(sm);
            if(result>0){
                r.setCode(200);
                r.setMsg("归档成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统开小差，请联系管理员");
        }

        return r;
    }

    @Override
    public R updateServiceManagementById(Problem p) {
        R r = new R();
        try {
            int result = serviceDao.updateServiceManagementById(p);
            if(result>0){
                r.setCode(200);
                r.setMsg("修改成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统开小差，请联系管理员");
        }

        return r;
    }

    @Override
    public R addServiceManagementById(Problem p) {
        R r = new R();
        try {
            int result = serviceDao.addServiceManagementById(p);
            if(result>0){
                r.setCode(200);
                r.setMsg("添加成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统开小差，请联系管理员");
        }

        return r;
    }
}
